package com.dinglit.dao;

import com.dinglit.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by liuhuanchao on 2018/8/5.
 */
@Mapper
public interface UserMapper {

    @Select("select * from user where id = #{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "userName", column = "user_name"),
            @Result(property = "userAge", column = "user_age"),
            @Result(property = "userAddress", column = "user_address") })

    User selectUserById(int id);

    @Select("select * from user where user_name = #{userName}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "userName", column = "user_name"),
            @Result(property = "userAge", column = "user_age"),
            @Result(property = "userAddress", column = "user_address") })
    List<User> selectUserByName(String userName);

    @Insert("insert into user(user_name,user_age,user_address) values (#{userName},#{userAge},#{userAddress})")
    int addUser(User user);

    @Update("update user set user_name=#{userName},user_age=#{userAge},user_address=#{userAddress} where id=#{id}")
    int updateUser(User user);

    @Delete("delete from user where id=#{id}")
    int deleteUser(int id);

}